# game_defs.py


# 棋盘尺寸
BOARD_SIZE = 7

# 棋盘初始化
board = [[' ' for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)]
board[0] = ['@', '-', '-', '@', '-', '-', '@']
board[1] = ['|', '@', '-', '@', '-', '@', '|']
board[2] = ['|', '|', '@', '@', '@', '|', '|']
board[3] = ['@', '@', '@', ' ', '@', '@', '@']
board[4] = ['|', '|', '@', '@', '@', '|', '|']
board[5] = ['|', '@', '-', '@', '-', '@', '|']
board[6] = ['@', '-', '-', '@', '-', '-', '@']

# 输出当前棋盘状态
def print_board():
    print('  ' + ' '.join([chr(ord('A') + i) for i in range(BOARD_SIZE)]))
    for i in range(BOARD_SIZE):
        print(str(i + 1) + ' ' + ' '.join(board[i]))

# 落子
def place_piece(row, col, piece):
    if row < 0 or row >= BOARD_SIZE or col < 0 or col >= BOARD_SIZE:
        return False
    if board[row][col] != '@':
        return False
    board[row][col] = piece
    return True

# 移动棋子
def move_piece(src_row, src_col, dst_row, dst_col):
    if src_row < 0 or src_row >= BOARD_SIZE or src_col < 0 or src_col >= BOARD_SIZE:
        return False
    if dst_row < 0 or dst_row >= BOARD_SIZE or dst_col < 0 or dst_col >= BOARD_SIZE:
        return False
    if board[src_row][src_col] == '@' or board[dst_row][dst_col] != ' ':
        return False
    board[dst_row][dst_col] = board[src_row][src_col]
    board[src_row][src_col] = '@'
    return True

# 吃子
def capture_piece(row, col):
    if row < 0 or row >= BOARD_SIZE or col < 0 or col >= BOARD_SIZE:
        return False
    if board[row][col] == ' ':
        return False
    board[row][col] = '@'
    return True
